/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import com.opensymphony.xwork2.ActionContext;
import java.util.Map;
import myconfession.dao.AccountDAO;
import myconfession.dto.account.Account;

/**
 *
 * @author Liem
 */
public class LoginAction {

    private String username;
    private String password;
    private String error;

    public LoginAction() {
    }

    public String execute() throws Exception {
        String sResult = "fail";
        Map session = ActionContext.getContext().getSession();
        Account acc = AccountDAO.checkLogin(getUsername(), getPassword());
        if (acc != null) {
            sResult = "success";
            session.put("USER", acc.getUsername());
            session.put("FULLNAME", acc.getFirstname() + " " + acc.getLastname());
            if (acc.getFbToken() != null) {
                session.put("HASTOKEN", "true");
            }
        } else {
            error = "Invalid username or password";
        }
        return sResult;
    }

    /**
     * @return the username
    public String getUsername() {
    return username;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }
}
